home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.orig.lzh / expire / histinfo.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  3KB  |  127 lines

  1. /*
  2.  * histinfo - print history file lines for articles named on stdin
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>        /* for modified time (date received) */
  8. #include "config.h"
  9.  
  10. #define MAXLINE 1024
  11. #define STRLEN(s) (sizeof(s) - 1)    /* s must be a char array */
  12.  
  13. char *progname;
  14. int debug;
  15.  
  16. FILE *efopen();
  17.  
  18. char *spdir;
  19. int spdirlen;
  20.  
  21. /*
  22.  * main - parse arguments and handle options
  23.  */
  24. main(argc, argv)
  25. int argc;
  26. char *argv[];
  27. {
  28.     int c;
  29.     int errflg = 0;
  30.     FILE *in;
  31.     char inname[MAXLINE];
  32.     extern int optind;
  33.     extern char *optarg;
  34.  
  35.     progname = argv[0];
  36.     while ((c = getopt(argc, argv, "d")) != EOF)
  37.         switch (c) {
  38.         case 'd':
  39.             ++debug;
  40.             break;
  41.         default:
  42.             errflg++;
  43.             break;
  44.         }
  45.     if (optind < argc || errflg) {
  46.         (void) fprintf(stderr, "usage: %s [-d]\n", progname);
  47.         exit(2);
  48.     }
  49.  
  50.     spdir = artfile((char *)NULL);
  51.     spdirlen = strlen(spdir);
  52.     
  53.     while (fgets(inname, sizeof(inname), stdin) != NULL) {
  54.         inname[strlen(inname)-1] = '\0';    /* kill newline */
  55.         in = efopen(inname, "r");
  56.         process(in, inname);
  57.         (void) fclose(in);
  58.     }
  59.     exit(0);
  60. }
  61.  
  62. /*
  63.  * process - process input file
  64.  */
  65. process(in, inname)
  66. FILE *in;
  67. char *inname;
  68. {
  69.     char *nl, *files;
  70.     char line[MAXLINE], msgid[MAXLINE], expiry[MAXLINE];
  71.     char datercv[30];
  72.     struct stat statb;
  73.     static char msgidnm[] =  "Message-ID: ";
  74.     static char expnm[] =    "Expires: ";
  75.     register char *p;
  76.     extern char *strrchr();
  77.     extern char *strchr();
  78.     extern char *strcpy();
  79.  
  80.     /* set defaults */
  81.     (void) strcpy(expiry, "-");
  82.     (void) strcpy(msgid, "<swill@trash>");
  83.  
  84.     /* read until EOF or blank line (end of headers) */
  85.     while (fgets(line, sizeof line, in) != NULL && strcmp(line, "\n") != 0) {
  86.         if ((nl = strrchr(line, '\n')) != NULL)
  87.             *nl = '\0';            /* trim newline */
  88.         if (strncmp(line, msgidnm, STRLEN(msgidnm)) == 0)
  89.             (void) strcpy(msgid, line+STRLEN(msgidnm));
  90.         else if (strncmp(line, expnm, STRLEN(expnm)) == 0)
  91.             (void) strcpy(expiry, line+STRLEN(expnm));
  92.     }
  93.  
  94.     /* generate the file name */
  95.     files = inname;
  96.     if (strncmp(files, spdir, spdirlen) == 0 &&
  97.         files[spdirlen] == '/')
  98.         files += spdirlen + 1;    /* skip spool dir. & slash */
  99.  
  100.     /* generate the date received */
  101.     (void) fstat(fileno(in), &statb);
  102.     (void) sprintf(datercv, "%ld", statb.st_mtime);
  103.  
  104.     /* de-tab the message id */
  105.     for (p = strchr(msgid, '\t'); p != NULL; p = strchr(p, '\t'))
  106.         *p = ' ';
  107.  
  108.     /* whomp out the history line */
  109.     (void) fputs(msgid, stdout);
  110.     (void) putchar('\t');
  111.     (void) fputs(datercv, stdout);
  112.     (void) putchar('~');
  113.     (void) fputs(expiry, stdout);
  114.     (void) putchar('\t');
  115.     (void) fputs(files, stdout);
  116.     (void) putchar('\n');
  117.     (void) fflush(stdout);
  118. }
  119.  
  120. /*
  121.  * unprivileged - no-op to keep pathname stuff happy
  122.  */
  123. void
  124. unprivileged()
  125. {
  126. }
  127.